package com.hj.ct.view;

import com.hj.ct.R;
import com.hj.ct.util.FileUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomDialog extends Dialog {
	private TextView tvTitle;
	private ImageView imgMessage;
	private TextView tvMessage;
	private Button btnLeft, btnRight, btnOnlyOne;
	private View viewOneBtn, viewTwoBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

	}

	public CustomDialog(Context context) {
		// TODO Auto-generated constructor stub
		super(context, R.style.dialog);
		initView();

	}

	private void initView() {
		setContentView(R.layout.custom_dialog);
		tvTitle = (TextView) findViewById(R.id.tv_dialog_title);
		imgMessage = (ImageView) findViewById(R.id.img_dialog_message);
		tvMessage = (TextView) findViewById(R.id.tv_dialog_message);
		btnLeft = (Button) findViewById(R.id.btn_dialog_left);
		btnRight = (Button) findViewById(R.id.btn_dialog_right);
		btnOnlyOne = (Button) findViewById(R.id.btn_dialog);
		viewOneBtn = findViewById(R.id.view_one_button);
		viewTwoBtn = findViewById(R.id.view_two_button);
		viewOneBtn.setVisibility(View.GONE);
		viewTwoBtn.setVisibility(View.GONE);
		Window window = this.getWindow();
		window.setGravity(Gravity.CENTER);
	}

	public void setTitile(String title) {
		tvTitle.setText(title);
	}

	public void setImageMessage(int resid) {
		imgMessage.setImageResource(resid);
		imgMessage.setVisibility(View.VISIBLE);
		tvMessage.setVisibility(View.GONE);
	}
	public void setImageMessage(String imgPath,int defaultImageRes) {
		imgMessage.setVisibility(View.VISIBLE);
		tvMessage.setVisibility(View.GONE);
		
		DisplayImageOptions options = new DisplayImageOptions.Builder()
		.showImageOnLoading(defaultImageRes)
		.showImageForEmptyUri(defaultImageRes)
		.showImageOnFail(defaultImageRes)
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.considerExifParams(true).displayer(new SimpleBitmapDisplayer()).build();
	   ImageLoader.getInstance().displayImage(imgPath, imgMessage, options);
	}

	public void setMessage(int resid) {
		tvMessage.setText(resid);
		imgMessage.setVisibility(View.GONE);
		tvMessage.setVisibility(View.VISIBLE);
	}

	public void setMessage(String message) {
		tvMessage.setText(message);
		imgMessage.setVisibility(View.GONE);
		tvMessage.setVisibility(View.VISIBLE);
	}

	public void setOnlyOneBtn(String onlyOne) {
		btnOnlyOne.setText(onlyOne);
		viewOneBtn.setVisibility(View.VISIBLE);
		viewTwoBtn.setVisibility(View.GONE);
	}

	public void setLeftBtn(String leftBtn) {
		btnLeft.setText(leftBtn);
		viewOneBtn.setVisibility(View.GONE);
		viewTwoBtn.setVisibility(View.VISIBLE);
	}

	public void setRightBtn(String rightBtn) {
		btnRight.setText(rightBtn);
		viewOneBtn.setVisibility(View.GONE);
		viewTwoBtn.setVisibility(View.VISIBLE);
	}

	public void setOnlyOneBtnOnclickListener(android.view.View.OnClickListener onlyOneBtnOnClickListener) {
		btnOnlyOne.setOnClickListener(onlyOneBtnOnClickListener);
	}

	public void setLeftBtnOnclickListener(android.view.View.OnClickListener leftBtnOnClickListener) {
		btnLeft.setOnClickListener(leftBtnOnClickListener);
	}

	public void setRightBtnOnclickListener(android.view.View.OnClickListener rightBtnOnClickListener) {
		btnRight.setOnClickListener(rightBtnOnClickListener);
	}

}
